package com.smartjobs.action;

import java.util.ArrayList;
import com.opensymphony.xwork2.ActionSupport;
import com.smartjobs.bean.JobPostingVO;
import com.smartjobs.loader.RDFLoader;
import com.smartjobs.reasoner.ReasonerQuery;

@SuppressWarnings("serial")
public class JobPostingAction extends ActionSupport {

	private ArrayList<JobPostingVO> jobpostings = new ArrayList<JobPostingVO>();
	String company = "";
	String location = "";
	String skills = "";

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getSkills() {
		return skills;
	}

	public void setSkills(String skills) {
		this.skills = skills;
	}

	public ArrayList<JobPostingVO> getJobpostings() {
		return jobpostings;
	}

	public void setJobpostings(ArrayList<JobPostingVO> jobpostings) {
		this.jobpostings = jobpostings;
	}

	public String execute() {
		int i;
		ArrayList<JobPostingVO> jobPostingList = new ArrayList<JobPostingVO>();
		RDFLoader.loadFromDataBase();
		jobPostingList = new ReasonerQuery().getAllJobs();
		for (i = 0; i < jobPostingList.size(); i++) {
			if ((jobPostingList.get(i).getCompanyName().toLowerCase()
					.contains(company.toLowerCase()))
					&& (jobPostingList.get(i).getLocation().toLowerCase()
							.contains(location.toLowerCase()))
					&& (jobPostingList.get(i).getSkills().toLowerCase()
							.contains(skills.toLowerCase()))) {
				jobpostings.add(jobPostingList.get(i));
			}
		}
		return SUCCESS;
	}

	public String init() {
		return SUCCESS;

	}

}
